﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using E5_KhuyenMaiVang.Models;

namespace E5_KhuyenMaiVang.Controllers
{
    public class ProduceController : Controller
    {
        //
        // GET: /DetailProduce/
        private GoldDealEntities dbGoldDeal = new GoldDealEntities();

        public ActionResult Detail(int dealID)
        {
            //Tao 1 lop DealsView trong Models, voi cac thuoc tinh giong nhu ten cac cot trong bang DEAL
            //Tao 1 class DealsManager trong Models, viet ham lay deal voi tham so id duoc truyen vao: DealsView GetDeal(int dealID)
            //Goi ham lay deal voi id = dealID o tren, roi tra ve deal vua lay.  return View(GetDeal(dealID));
            //Trong View Detail khai bao dong tren cung la:  @model E5_KhuyenMaiVang.Models.DealsView
            //roi su dung:  @Html.DisplayFor(model => model.Discription) de hien thi du lieu
            //neu muon su dung gia tri 1 thuoc tinh nao do: id = Model.Discription . 
            var deal = dbGoldDeal.DEAL.Single(p => p.DealID == dealID);
            ViewBag.CurrentDeal = deal;
            var listComments = dbGoldDeal.COMMENT.Where(p => p.DealID == dealID);
            return View(listComments);
        }

        [HttpPost]
        public ActionResult PostComment(string Name, string Email, string Content,int dealID) {
            COMMENT comment = new COMMENT();
            comment.PostName = Name;
            comment.Text = Content;
            comment.DealID = dealID;
            comment.PostDate = System.DateTime.Now;
            dbGoldDeal.AddToCOMMENT(comment);
            dbGoldDeal.SaveChanges();
            var deal = dbGoldDeal.DEAL.Single(p => p.DealID == dealID);
            ViewBag.CurrentDeal = deal;
            var listComments = dbGoldDeal.COMMENT.Where(p => p.DealID == dealID);
            return View("Detail", listComments);            
        } 

        public ActionResult GioHang()
        {
            return View();
        }

        public ActionResult ThanhToan()
        {
            return View();
        }
    }
}
